import React from 'react';
import {connect} from 'react-redux';
import {Switch, Route} from 'react-router-dom';
import {NavBar} from 'antd-mobile';
import NavLinkBar from '../navLink/NavLinkBar';
import Boss from "../../component/boss/Boss";
import Genius from "../../component/genius/Genius";
import User from '../user/User';
import Msg from '../../component/msg/Msg';
import {getMsgList, recvMsg} from "../../redux/chat.redux";


@connect(
    state => state,
    {getMsgList, recvMsg}
)
class DashBoard extends React.Component {

    componentDidMount(){
        if(!this.props.chat.chatmsg.length) {
            this.props.getMsgList();
            this.props.recvMsg();
        }
    }

    render() {
        const user = this.props.user;
        const {pathname} = this.props.location;
        const navList = [{
            path: '/boss',
            text: '牛人',
            icon: 'boss',
            title: '牛人列表',
            component: Boss,
            hide: user.type === 'genius'
        }, {
            path: '/genius',
            text: 'BOSS',
            icon: 'user',
            title: 'boss列表',
            component: Genius,
            hide: user.type === 'boss'
        }, {
            path: '/msg',
            text: '消息',
            icon: 'msg',
            title: '消息列表',
            component: Msg
        }, {
            path: '/me',
            text: '我',
            icon: 'user',
            title: '个人中心',
            component: User
        }];
        return (
            <div>
                <NavBar mode={'dark'} className='fixed-header'>
                    {navList.find(v => v.path === pathname).title}
                </NavBar>
                <div style={{marginTop: 15}}>
                    <Switch>
                        {
                            navList.map(v => (
                                <Route key={v.path} path={v.path} component={v.component}/>
                            ))
                        }
                    </Switch>
                </div>
                <NavLinkBar data={navList} />
            </div>
        )
    }
}

export default DashBoard;